﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MailServer.Client {
    [Serializable]
    public class Wrap {
        private Server.Server server;
        private Recipient.Recipient recipient;

        public Wrap(Server.Server server, string user) {
            this.server = server;
            recipient = new Recipient.Recipient();
        }

        public List<Message.Message> List(string user) {
            return recipient.List(user);
        }

        public List<Message.Message> ListFrom(string user, string from) {
            return recipient.ListFrom(user, from);
        }

        public void SetReaded(Message.Message message) {
            recipient.SetReaded(message);
        }

        public bool IsReaded(Message.Message message) {
            return recipient.IsReaded(message);
        }

        public int GetMessageWaitingServer(string user) {
            return server.GetMessageWaiting(user);
        }

        public void SyncMessages(string user) {
            List<Message.Message> messages = server.GetNewMessages(user);
            foreach(Message.Message theMessage in messages)
                recipient.Add(theMessage);
        }

        public void RemoveMessage(Message.Message message) {
            recipient.Remove(message);
            server.RemoveMessage(message);
        }

        public void Post(Message.Message message) {
            server.Post(message);
        }
    }
}
